//
//  UIImageView+DCWebCache.m
//  DCWebImage
//
//  Created by Joinwe on 16/6/1.
//  Copyright © 2016年 Joinwe. All rights reserved.
//

#import "UIImageView+DCWebCache.h"


@implementation UIImageView (DCWebCache)

- (void)setImageWithURLString:(NSString *)urlString placeholederImage:(UIImage *)image{
    //先使用占位图
    self.image = image;
    
    [self setImageWithURLString:urlString];
}


- (void)setImageWithURLString:(NSString *)urlString{
    DCImageCache *imageCache = [DCImageCache sharedImageCache];
    
    UIImage *image = nil;
    //1.从内存中查找图片
    image = [imageCache seachImageFromMemoryWithURLString:urlString];
    if (image != nil) {
        self.image = image;
        return;
    }
    
    //2.从沙盒中照图片
    image = [imageCache searchImageFromSandBoxWithURLString:urlString];
    if (image != nil) {
        self.image = image;
        return;
    }
    
    
    //3.从网络上获取
    [imageCache downloadImageWithURLString:urlString completionBlock:^(UIImage *image) {
        self.image = image;
    }];
}

@end
